C# 回车(键盘)事件

您所在的位置:网站首页 Excel 按键事件 C# 回车(键盘)事件

C# 回车(键盘)事件

2023-08-01 01:17| 来源: 网络整理| 查看: 265

在KeyPress事件中     private   void   textBox1_KeyPress(object   sender,   System.Windows.Forms.KeyPressEventArgs   e)     {     if(e.KeyChar==(char)13)     {     this.textBox2.Focus();     }     }===================================================================================  private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)     {        //if条件检测按下的是不是Enter键           if(e.KeyCode==Keys.Enter)           {                 MessageBox.Show("您在textBox1里按下了回车键");           }     } 

C#回车键事件写法是什么呢?我们经常看到程序执行之后会有回车键的出现,那么具体的实现方法是什么呢?C#中回车键事件是如何实现的呢?让我们看看具体的过程:

C#回车键事件1.

private void textBox1_KeyDown(  object sender,   System.Windows.Forms.KeyEventArgs e)    {    if(e.KeyValue==13)    {    MessageBox.Show("你摁下了回车");    }    }   

C#回车键事件2.

public partial class Form1 : Form   {   public Form1()   {   InitializeComponent();    this.textBox1.KeyDown +=   new KeyEventHandler(textBox1_KeyDown);    this.button1.Click +=   new EventHandler(btnOK_Click);   }   void button1_Click(object sender, EventArgs e) { }    void textBox1_KeyDown(object sender, KeyEventArgs e)    {   if (e.KeyCode == Keys.Enter)   {   this.button1_Click(button1, null);   //这个地方用button1.PerformClick()应该更合适//在TextBox按Enter键就执行button1的单击事件   //如果你要用引发的话要用到api   }    }    }   

C#回车键事件的写法就向你介绍到这里,希望对你了解和学习C#回车键事件有所帮助



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3